import {createStore} from 'vuex'

export default createStore({
	state: {
		"token": uni.getStorageSync('token') || '',
		"userinfo": JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		"updatetime":uni.getStorageSync('updatetime') || 0
	},
	mutations: {
		updateUserInfo(state, userinfo) {
			state.userinfo = userinfo;
			this.commit('saveUserInfoToStorge');
		},
		saveUserInfoToStorge(state) {
			uni.setStorageSync('userinfo', JSON.stringify(state.userinfo));
		},
		updateToken(state, token) {
			state.token = token
			this.commit('saveTokenToStorge')
		},
		saveTokenToStorge(state) {
			uni.setStorageSync('token', state.token);
		},
		updateUpdatetime(state, updatetime) {
			state.updatetime = updatetime
			this.commit('saveUpdatetime')
		},
		saveUpdatetime(state) {
			uni.setStorageSync('updatetime', state.updatetime)
		}
	}
})